package com.example.demo.algorithm.test;

public class TwoSumDemo {

    public static void main(String[] args) {
        int[] nums = new int[]{2, 7, 11, 15};
        int target = 13;
        int[] myIndex = twoSum(nums, target);
        for (int index : myIndex) {
            System.out.println(index);
        }
    }

    public static int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            int sum;
            for (int j = nums.length - 1; j > 0; j--) {
                sum = nums[i] + nums[j];
                if (sum == target) {
                    return new int[]{i, j};
                }
            }
        }
        return null;
    }

}
